 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="demo2">
        {{date}}
    </div>
<script src="https://unpkg.com/vue@2.6.1/dist/vue.min.js"></script>
<script>
    var demo2 = new Vue({
        el: '#demo2',
        data: {
            date: new Date()
        },
        mounted: function () {
            var _this = this; //声明一个变量指向Vue实例this，保持作用域一致
            this.timer = setInterval(function () {
                _this.date = new Date();//修改数据
            },1000)
        },
        beforeDestroy: function () {
            if(this.timer){
                clearInterval(this.timer);//在Vue实例销毁前，清除我们的定时器
            }
        }
    });

</script>
</body>
</html>